xhr = false;

function Go(params)
{ 
	var url = 'index.php?'+params;
	makeRequest(url);
	return false;
}

function Add(params)
{ 
	var url = 'add.php?nazwa='+document.getElementById('nazwa').value+params;
	makeRequest(url);
    setTimeout("del()", 2000);
	return false;
}

function Update(id,val)
{ 
	if (document.getElementById('nazwa'+id).value!=val)
	{
		var url = 'update.php?nazwa='+document.getElementById('nazwa'+id).value+'&id='+id;
		makeRequest(url);
		setTimeout("del()", 2000);
	}
	else
	{
		document.getElementById(id).innerHTML = val;
	}
	return false;
}

function deleteurl(id)
{ 

	var url = 'del.php?id='+id;
	makeRequest(url);
	document.getElementById('v'+id).innerHTML = '';
	return false;
}

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }


function dele(id,val)
{ 
	document.getElementById('quest').style.top = findPosY(document.getElementById(id))-50+'px';
	document.getElementById('quest').innerHTML = '<div class="ques" id="quest">Czy napewno usunac film: '+val+'<br><a href="javascript:void(0)" onclick="deletemovie('+id+')">Tak</a> <a href="javascript:void(0)" onclick="cls()">Nie</a></div>';
}

function cls()
{ 
	document.getElementById('quest').innerHTML = '';
}


function makeRequest(url)
{
    if (window.XMLHttpRequest)
    {
        xhr= new XMLHttpRequest();
    }
    else
    {
        if (window.ActiveXObject)
        {
            try
            {
                xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {

            }
        }
    }
    if(xhr)
    {
        xhr.onreadystatechange = showContents;
        xhr.open("GET", url, true);
		xhr.setRequestHeader('Content-Type', 'text/html; charset=UTF-8');
        xhr.send(null);
    }
    else 
    {
        document.getElementById("info").innerHTML = "Nie udało się utworzyć obiektu XMLHttpRequest";
    }
}

function showContents()
{
    if (xhr.readyState == 4)
    {
        if (xhr.status == 200)
        {
            var outMsg = (xhr.responseXML && xhr.responseXML.contenttype == "text/xml") ? xhr.responseXML.getElementByTagName("choices")[0].textContent : xhr.responseText;
        }
        else 
        {
            var outMsg = "Wystapił problem z żądaniem ";
        }
        document.getElementById("info").innerHTML = outMsg;
    }
}

function anuluj(id,val)
{
	document.getElementById(id).innerHTML = val;

}
	  
function makeedit(id,val)
{
	var s = '<input class="button" type="text" id="nazwa'+id+'" name="nazwa" value="'+val+'" size="50"><img src="./img/okay.png" onclick="Update('+id+',\''+val+'\')"><img src="./img/no.png" onclick="anuluj('+id+',\''+val+'\')">';
	document.getElementById(id).innerHTML = s;
} 